package org.company.earth.spring;

import org.company.earth.service.ITaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Component;

@Component
public class TaskSchedule {
    
    private class Task implements Runnable {
        
        private ITaskService task;
        
        public Task(ITaskService task) {
            this.task = task;
        }
        
        @Override
        public void run() {
            // TODO Auto-generated method stub
            task.execute();
        }
    }
    
    @Autowired
    @Qualifier("taskExecutor")
    private TaskExecutor taskPool;
    
    public void execute(ITaskService task) {
        taskPool.execute(new Task(task));
    }
    
}
